<!--就诊人组件-->
<template>
  <div class="visitor">
    <div class="top">
      <div class="left">
        <!--<span class="free1" v-show="user.isInsure==1">医保</span>-->
        <!--<span class="free2" v-show="user.isInsure==0" >自费</span>-->
        <span class="free1" v-if="user.isInsure==1">医保</span>
        <span class="free2" v-if="user.isInsure==0" >自费</span>
        <span class="username">{{user.name}}</span>
      </div>
      <div class="right">
        <el-button circle type="primary" size="default" :icon="Edit" @click="changeSceneHandler"></el-button>
        <el-popconfirm v-on:confirm="removeUser" :title="`确定删除 ${user.name} ?`" width="200px">
          <template #reference>
            <el-button v-if="$route.path=='/user/patient'" circle type="danger" size="default" :icon="Delete"></el-button>
          </template>
        </el-popconfirm>
      </div>
    </div>
    <div class="bottom">
      <p>证件类型：{{user.param.certificatesTypeString}}</p>
      <p>证件号码：{{user.certificatesNo}}</p>
      <p>用户性别：{{user.sex==0?"女士":"男士"}}</p>
      <p>出生日期：{{user.birthdate}}</p>
      <p>手机号码：{{user.phone}}</p>
      <p>婚姻状况：{{user.isMarry==0?"未婚":"已婚" }}</p>
      <p>当前住址：{{user.param.cityString}}</p>
      <p>详细地址：{{user.param.fullAddress}}</p>
      <!--已选择-->
      <transition name="confirm">
        <div class="confirm" v-if="index === currentIndex">已选择</div>
      </transition>

    </div>
  </div>
</template>

<script setup lang="ts">
import {Edit,Delete} from "@element-plus/icons-vue";
import {useRoute, useRouter} from "vue-router";
import {reqRemoveUser} from "@/api/user";
import {ElMessage} from "element-plus";

let $emit = defineEmits(["changeScene","removeUser"]);

//接收父组件传递过来的就诊人信息
let props = defineProps(["user","index","currentIndex"]);

//
let $route = useRoute();
let $router = useRouter();

//就诊人组件修改按钮的回调
const changeSceneHandler = () => {
  //就诊人管理模块点击修改按钮
  if ($route.path == "/user/patient") {
    $emit('changeScene', props.user);
  } else {
    //预约挂号点击修改按钮
    $router.push({path:'/user/patient',query:{type:'edit', id: props.user.id}});
  }
}

//删除用户
const removeUser = async () => {
  let result: any = await reqRemoveUser(props.user.id);
  if (result.code == 200) {
    ElMessage({
      showClose:true,
      message:"删除成功",
      type:"success"
    });
    $emit("removeUser");
  }
}

</script>

<style scoped lang="scss">
.visitor {
  box-shadow: 0px 0px 12px rgb(0, 0, 0, 0.15);
  .top {
    height: 45px;
    background: #e5e5e5;
    display: flex;
    justify-content: space-around;//左右派来两端有距离
    align-items: center;//水平对齐
    .left {
      display: flex;
      align-items: center;
      .free1 {
        background: #97fa69;
        padding: 1px 3px 3px 3px;
        font-size: 15px;
        margin: 5px;
        border-radius: 4px;
        width: auto;
      }
      .free2 {
        background: white;
        padding: 1px 3px 3px 3px;
        font-size: 15px;
        margin: 5px;
        border-radius: 3px;
        width: auto;
      }
      .username {
        font-size: 17px;
        color: #7f7f7f;
        padding: 0px 3px 0px 3px;
      }
    }
  }
  .bottom {
    position: relative;
    //padding-left: 45px;
    padding: 10px 15px;
    p{
      margin: 5px 0px;
      line-height: 25px;
    }
    .confirm {
      position: absolute;
      width: 200px;
      height: 200px;
      color: red;
      border-radius: 50%;
      border: 3.5px dashed red;
      text-align: center;
      line-height: 200px;
      left: 17%;
      top: 15%;
      opacity: 0.5;
      transform: rotate(35deg);
      font-size: 25px;
      font-weight: 900;
    }
    .confirm-enter-from {
      transition:scale(1);
    }
    .confirm-enter-active {
      transition: all 0.3s;
    }
    .confirm-enter-to {
      transform:scale(1.2);
    }
  }
}
</style>